/**
 * @Author:Geln Yang
 * @Created:2008-8-3
 * $ Revision: 1.0 $
 * $ Author: Geln Yang $
 * $ Date: 2008-8-3 $
 */
package org.geln.web.webwork.interceptor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geln.web.Constants;

import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
import com.opensymphony.xwork.util.LocalizedTextUtil;

/**
 * @Author:Geln Yang
 * @Created:2008-8-3
 */
public class ExceptionInterceptor implements Interceptor {
	private static final Log log = LogFactory.getLog(ExceptionInterceptor.class);

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		try {
			return invocation.invoke();
		} catch (Exception e) {
			String message = LocalizedTextUtil.findText(this.getClass(), "unknow.action.exception", ActionContext
					.getContext().getLocale(), "Caught exception while invoking action:{0}", new String[] { invocation
					.getAction().getClass().getName() });
			log.error(message, e);
			invocation.getStack().push(new ExceptionHolder(message, e));
			return Constants.EXCEPTION;
		}
	}
}
